package com.wanmait.wanmarecruit.webController;

import com.github.pagehelper.PageInfo;
import com.wanmait.wanmarecruit.entity.Company;
import com.wanmait.wanmarecruit.entity.Position;
import com.wanmait.wanmarecruit.service.CompanyPicService;
import com.wanmait.wanmarecruit.service.CompanyService;
import com.wanmait.wanmarecruit.service.PositionService;
import org.apache.ibatis.annotations.Param;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;

import javax.annotation.Resource;

@Controller
@RequestMapping("web")
public class WebPersonalCompanyDetailController {

    @Resource
    private CompanyService companyService;
    @Resource
    private PositionService positionService;
    @Resource
    private CompanyPicService companyPicService;

    //去公司详情页面（张佳炜）
    @RequestMapping("/personal/personalCompanyDetail/{companyId:\\d+}")
    public ModelAndView goPersonalCompanyDetail(@PathVariable Integer companyId)
    {
        ModelAndView modelAndView = new ModelAndView();
        modelAndView.addObject("company",companyService.selectCompanyByCompanyId(companyId));
        modelAndView.addObject("companyPics",companyPicService.getCompanyPicByCompanyId(companyId));
        modelAndView.setViewName("/web/personal/personalCompanyDetail");
       return modelAndView;
    }
    //ajax通过companyId查询所有的公司对应的所有招聘岗位(张佳炜）
    @RequestMapping("/personal/personalCompanyDetailData")
    @ModelAttribute("positionPageInfo")
    public PageInfo<Position> selectAllPositionByCompanyId(Integer pageNum,Integer companyId)
    {
        if (pageNum<=0)
        {
            pageNum=1;
        }
        Integer pageSize=4;
        return positionService.selectAllPositionByCompanyId(pageNum,pageSize,companyId);
    }
}
